{extend name="Base" /}
{block name="title"}{$title}{/block}
{block name="body"}
{load href="/js/backend/lodash.min.js"}
<link rel="stylesheet" type="text/css" href="/css/backend/custom.css?{:VER}"/>
<!--<script type='text/javascript' src='/js/backend/custom.js?{:VER}'></script>-->
<style>
	.layui-input-inline {
		min-width: 180px;
	}
</style>
<div class="layui-tab layui-tab-brief" lay-filter="tab">
	<ul class="layui-tab-title">
		<li class="layui-this">{$name1}</li>
		<li lay-id="1">{$name2}</li>
		<li lay-id="2">{$name3}</li>
	</ul>
	<div class="layui-tab-content">
		<div class="layui-tab-item layui-show group-tab">
			<form class="layui-form layui-form-pane">
				<div class="layui-form-item">
					<label class="layui-form-label">选择用户组</label>
					<div class="layui-input-inline">
						<select class="group" name="group" lay-filter="group"></select>
					</div>
					<button type="button" class="layui-btn groupadd" data-type="groupadd">新增用户组</button>
					<button type="button" class="layui-btn layui-btn-danger groupdel" data-type="groupdel">删除用户组</button>
					<button type="button" class="layui-btn layui-btn-normal groupass" data-type="groupass">用户组赋权</button>
				</div>
			</form>
			<table id="group" lay-filter="group_table" class="layui-hide"></table>

			<script type="text/html" id="group_bar">
				<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
			</script>
		</div>

		<div class="layui-tab-item role-tab">
			<form class="layui-form layui-form-pane">
				<div class="layui-form-item">
					<label class="layui-form-label">选择角色</label>
					<div class="layui-input-inline">
						<select class="role" name="role" lay-filter="role"></select>
					</div>
					<button type="button" class="layui-btn roleadd" data-type="roleadd">新增角色</button>
					<button type="button" class="layui-btn layui-btn-danger roledel" data-type="roledel">删除角色</button>
					<button type="button" class="layui-btn layui-btn-normal roleass" data-type="roleass">角色赋权</button>
				</div>
			</form>
			<table id="role" lay-filter="role_table" class="layui-hide"></table>

			<script type="text/html" id="role_bar">
				<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
			</script>
		</div>

		<div class="layui-tab-item per-tab">
			<div class="layui-inline">
				<div class="layui-input-inline">
					<input type="text" name="name" placeholder="权限名称" autocomplete="off" class="layui-input">
				</div>
				<div class="layui-input-inline">
					<input type="text" name="description" placeholder="权限描述" autocomplete="off" class="layui-input">
				</div>
				<div class="layui-input-inline">
					<input type="text" name="path" placeholder="权限控制路径" autocomplete="off" class="layui-input">
				</div>
				<div class="layui-input-inline">
					<input type="text" name="status" placeholder="权限状态" autocomplete="off" class="layui-input" value="1">
				</div>
			</div>
			<button type="button" class="layui-btn peradd" data-type="peradd">新增权限</button>
			<table id="per" lay-filter="per_table" class="layui-hide"></table>

			<script type="text/html" id="per_bar">
				<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
			</script>
		</div>
	</div>
</div>

<script id="check" type="text/html">
	<form class="layui-form layui-form-pane">
		<div class="layui-form-item">
			<div class="layui-input-block">
				<%# layui.each(d, function(i, item){ %>
				<%# if(item.id === item.roleid || item.id === item.perid){ %>
				<input type="checkbox" name="like<% item.id %>" value="<% item.id %>" title="<% item.name %>" checked>
				<%# } else { %>
				<input type="checkbox" name="like<% item.id %>" value="<% item.id %>" title="<% item.name %>">
				<%# }}); %>
				<%# if(d.length === 0){ %>无数据<%# } %>
			</div>
		</div>
		<div style="text-align: center">
			<button class="layui-btn layui-btn-normal submit" lay-submit>提交</button>
		</div>
	</form>
</script>

<script>
	layui.use(['form', 'layer', 'table', 'element', 'laytpl'], function () {
		var form = layui.form;
		var layer = layui.layer;
		var table = layui.table;
		var element = layui.element;
		var laytpl = layui.laytpl;

		table.render({
			id: "group",
			elem: '#group',
			page: true,
			height: 650,
			even: true,
			method: 'post',
			where: {
				groupid: 3,
				type: 1
			},
			url: "/backend/system/getGroupList",
			cols: [[
//				{field: 'id', title: '角色ID', width: 80},
				{space: true},
				{field: 'name', title: '角色名称', sort: true, width: 150, event: 'name', style: 'cursor: pointer;'},
				{field: 'description', title: '角色描述', sort: true, width: 500, event: 'description', style: 'cursor: pointer;'},

				{title: '操作', width: 80, align: 'center', toolbar: '#group_bar', fixed: 'right'}
			]]
		});

		$.ajax({
			type: "GET",
			url: "/backend/system/getGroupList",
			cache: false,
			dataType: "json",
			success: function (data) {
				var GROUP = data.data;
				var $group = $(".group");
				$group.empty();
				for (var i_GROUP in GROUP) {
					var o_GROUP = $("<option></option>");
					$(o_GROUP).val(GROUP[i_GROUP]['id']);
					$(o_GROUP).html(GROUP[i_GROUP]['name']);
					$group.append(o_GROUP);
				}
				form.render('select');
			}
		});

		element.on('tab(tab)', function (data) {
			if (Number(data.index) === 1) {
				table.render({
					id: "role",
					elem: '#role',
					page: true,
					height: 650,
					even: true,
					method: 'post',
					where: {
						roleid: 3,
						type: 1
					},
					url: "/backend/system/getRoleList",
					cols: [[
//						{field: 'id', title: '角色ID', width: 80},
						{space: true},
						{field: 'name', title: '权限名称', sort: true, width: 150, event: 'name', style: 'cursor: pointer;'},
						{field: 'description', title: '权限描述', sort: true, width: 500, event: 'description', style: 'cursor: pointer;'},

						{title: '操作', width: 80, align: 'center', toolbar: '#role_bar', fixed: 'right'}
					]]
				});

				$.ajax({
					type: "GET",
					url: "/backend/system/getRoleList",
					cache: false,
					dataType: "json",
					success: function (data) {
						var ROLE = data.data;
						var $role = $(".role");
						$role.empty();
						for (var i_ROLE in ROLE) {
							var o_ROLE = $("<option></option>");
							$(o_ROLE).val(ROLE[i_ROLE]['id']);
							$(o_ROLE).html(ROLE[i_ROLE]['name']);
							$role.append(o_ROLE);
						}
						form.render('select');
					}
				});
			} else if (Number(data.index) === 2) {
				table.render({
					id: "per",
					elem: '#per',
					page: true,
					height: 650,
					even: true,
					method: 'post',
					url: "/backend/system/getPermissionList",
					cols: [[
//						{field: 'id', title: '角色ID', width: 80},
						{space: true},
						{field: 'name', title: '权限名称', sort: true, width: 150, event: 'name', style: 'cursor: pointer;'},
						{field: 'description', title: '权限描述', sort: true, width: 500, event: 'description', style: 'cursor: pointer;'},
						{field: 'path', title: '控制路径，模块/控制器/方法，【*】全权限', sort: true, width: 320, event: 'path', style: 'cursor: pointer;'},
						{field: 'status', title: '权限状态，0=废弃，1=正常', sort: true, width: 300, event: 'status', style: 'cursor: pointer;'},

						{title: '操作', width: 80, align: 'center', toolbar: '#per_bar', fixed: 'right'}
					]]
				});
			}
		});

		var active = {
			groupadd: function () {
				layer.open({
					type: 1,
					title: '新增用户组',
					closeBtn: 1,
					area: '400px;',
					shade: 0.8,
					id: 'groupadd',
					btn: ['提交', '取消'],
					content: '<form class="layui-form layui-form-pane" style="padding:10px">' +
					'<div class="layui-form-item">' +
					'<label class="layui-form-label">名称</label>' +
					'<div class="layui-input-inline">' +
					'<input type="text" name="groupname" lay-verify="name" autocomplete="off" placeholder="请输入名称" class="layui-input">' +
					'</div>' +
					'</div>' +
					'<div class="layui-form-item">' +
					'<label class="layui-form-label">描述</label>' +
					'<div class="layui-input-inline">' +
					'<input type="text" name="groupdescription" lay-verify="description" autocomplete="off" placeholder="请输入描述" class="layui-input">' +
					'</div>' +
					'</div>' +
					'</form>',
					success: function (layero) {
						var btn = layero.find('.layui-layer-btn');
						btn.css('text-align', 'center');
						btn.find('.layui-layer-btn0').click(function () {
							var data = {
								name: $("input[name=groupname]").val(),
								description: $("input[name=groupdescription]").val()
							};
							$.ajax({
								type: "POST",
								url: "/backend/system/addGroup",
								cache: false,
								data: data,
								dataType: "json",
								success: function (e) {
									if (e.status === 1) {
										$.ajax({
											type: "GET",
											url: "/backend/system/getGroupList",
											cache: false,
											dataType: "json",
											success: function (data) {
												var GROUP = data.data;
												var $group = $(".group");
												$group.empty();
												for (var i_GROUP in GROUP) {
													var o_GROUP = $("<option></option>");
													$(o_GROUP).val(GROUP[i_GROUP]['id']);
													$(o_GROUP).html(GROUP[i_GROUP]['name']);
													$group.append(o_GROUP);
												}
												form.render('select');
											}
										});
										layer.alert(e.message, {
											//成功图标
											icon: 1
										});
									} else if (e.status === 0) {
										layer.alert(e.message, {
											//失败图标
											icon: 2
										});
									} else {
										layer.alert("系统错误，请稍后重试", {
											//失败图标
											icon: 2
										});
									}
								}
							});
						})
					}
				});
			},
			roleadd: function () {
				layer.open({
					type: 1,
					title: '新增角色',
					closeBtn: 1,
					area: '400px;',
					shade: 0.8,
					id: 'roleadd',
					btn: ['提交', '取消'],
					content: '<form class="layui-form layui-form-pane" style="padding:10px">' +
					'<div class="layui-form-item">' +
					'<label class="layui-form-label">名称</label>' +
					'<div class="layui-input-inline">' +
					'<input type="text" name="rolename" lay-verify="name" autocomplete="off" placeholder="请输入名称" class="layui-input">' +
					'</div>' +
					'</div>' +
					'<div class="layui-form-item">' +
					'<label class="layui-form-label">描述</label>' +
					'<div class="layui-input-inline">' +
					'<input type="text" name="roledescription" lay-verify="description" autocomplete="off" placeholder="请输入描述" class="layui-input">' +
					'</div>' +
					'</div>' +
					'</form>',
					success: function (layero) {
						var btn = layero.find('.layui-layer-btn');
						btn.css('text-align', 'center');
						btn.find('.layui-layer-btn0').click(function () {
							var data = {
								name: $("input[name=rolename]").val(),
								description: $("input[name=roledescription]").val()
							};
							$.ajax({
								type: "POST",
								url: "/backend/system/addRole",
								cache: false,
								data: data,
								dataType: "json",
								success: function (e) {
									if (e.status === 1) {
										$.ajax({
											type: "GET",
											url: "/backend/system/getRoleList",
											cache: false,
											dataType: "json",
											success: function (data) {
												var ROLE = data.data;
												var $role = $(".role");
												$role.empty();
												for (var i_ROLE in ROLE) {
													var o_ROLE = $("<option></option>");
													$(o_ROLE).val(ROLE[i_ROLE]['id']);
													$(o_ROLE).html(ROLE[i_ROLE]['name']);
													$role.append(o_ROLE);
												}
												form.render('select');
											}
										});
										layer.alert(e.message, {
											//成功图标
											icon: 1
										});
									} else if (e.status === 0) {
										layer.alert(e.message, {
											//失败图标
											icon: 2
										});
									} else {
										layer.alert("系统错误，请稍后重试", {
											//失败图标
											icon: 2
										});
									}
								}
							});
						})
					}
				});
			},
			peradd: function () {
				var data = {
					name: $("input[name=name]").val(),
					description: $("input[name=description]").val(),
					path: $("input[name=path]").val(),
					status: $("input[name=status]").val()
				};
				$.ajax({
					type: "POST",
					url: "/backend/system/addPer",
					cache: false,
					data: data,
					dataType: "json",
					success: function (e) {
						if (e.status === 1) {
							table.reload('per');
							$("input[name=name]").val("");
							$("input[name=description]").val("");
							$("input[name=path]").val("");
							$("input[name=status]").val("1");
							layer.alert(e.message, {
								//成功图标
								icon: 1
							});
						} else if (e.status === 0) {
							layer.alert(e.message, {
								//失败图标
								icon: 2
							});
						} else {
							layer.alert("系统错误，请稍后重试", {
								//失败图标
								icon: 2
							});
						}
					}
				});
			},
			groupdel: function () {
				var $select = $("select[name=group]").val(), $selecthtml = $("select[name=group] option:selected").html();
				layer.confirm('确认要删除【' + $selecthtml + '】么？', function (index) {
					layer.close(index);
					$.ajax({
						type: "POST",
						url: "/backend/system/delGroup",
						cache: false,
						data: {id: $select},
						dataType: "json",
						success: function (e) {
							if (e.status === 1) {
								$.ajax({
									type: "GET",
									url: "/backend/system/getGroupList",
									cache: false,
									dataType: "json",
									success: function (data) {
										var GROUP = data.data;
										var $group = $(".group");
										$group.empty();
										for (var i_GROUP in GROUP) {
											var o_GROUP = $("<option></option>");
											$(o_GROUP).val(GROUP[i_GROUP]['id']);
											$(o_GROUP).html(GROUP[i_GROUP]['name']);
											$group.append(o_GROUP);
										}
										form.render('select');
									}
								});
								table.reload('group', {
									where: {
										groupid: $select,
										type: 1
									}
								});
								layer.alert(e.message, {
									//成功图标
									icon: 1
								});
							} else if (e.status === 0) {
								layer.alert(e.message, {
									//失败图标
									icon: 2
								});
							} else {
								layer.alert("系统错误，请稍后重试", {
									//失败图标
									icon: 2
								});
							}
						}
					});
				});
			},
			roledel: function () {
				var $select = $("select[name=role]").val(), $selecthtml = $("select[name=role] option:selected").html();
				layer.confirm('确认要删除【' + $selecthtml + '】么？', function (index) {
					layer.close(index);
					$.ajax({
						type: "POST",
						url: "/backend/system/delRole",
						cache: false,
						data: {id: $select},
						dataType: "json",
						success: function (e) {
							if (e.status === 1) {
								$.ajax({
									type: "GET",
									url: "/backend/system/getRoleList",
									cache: false,
									dataType: "json",
									success: function (data) {
										var ROLE = data.data;
										var $role = $(".role");
										$role.empty();
										for (var i_ROLE in ROLE) {
											var o_ROLE = $("<option></option>");
											$(o_ROLE).val(ROLE[i_ROLE]['id']);
											$(o_ROLE).html(ROLE[i_ROLE]['name']);
											$role.append(o_ROLE);
										}
										form.render('select');
									}
								});
								table.reload('role', {
									where: {
										roleid: 3,
										type: 1
									}
								});
								layer.alert(e.message, {
									//成功图标
									icon: 1
								});
							} else if (e.status === 0) {
								layer.alert(e.message, {
									//失败图标
									icon: 2
								});
							} else {
								layer.alert("系统错误，请稍后重试", {
									//失败图标
									icon: 2
								});
							}
						}
					});
				});
			},
			groupass: function () {
				$.ajax({
					type: "GET",
					url: "/backend/system/getRoleList",
					cache: false,
					dataType: "json",
					success: function (e) {
						var $select = $("select[name=group]").val(), $selecthtml = $("select[name=group] option:selected").html(), tmp;
						laytpl.config({
							open: '<%',
							close: '%>'
						});
						var index = layer.open({
							type: 1,
							title: false,
							closeBtn: true,
							area: '950px;',
							shade: 0.8,
							id: 'groupass',
							content: '<div class="layui-form layui-form-pane" style="padding:10px">' +
							'<fieldset class="layui-elem-field layui-field-title">' +
							'<legend>' + $selecthtml + '</legend>' +
							'</fieldset>' +
							'<div id="view"></div>' +
							'</div>'
						});
						$.ajax({
							type: "POST",
							url: "/backend/system/getGroupList",
							cache: false,
							dataType: "json",
							async: false,
							data: {
								page: 0,
								limit: 10000,
								type: 1,
								groupid: $select
							}
						}).done(function (ee) {
							tmp = _.sortBy(_.unionBy(_.values(ee.data), _.values(e.data), 'id'), function (item) {
								return item.id;
							});
						});
						var getTpl = check.innerHTML, view = document.getElementById('view');
						laytpl(getTpl).render(tmp, function (html) {
							view.innerHTML = html;
						});
						form.render('checkbox');
						$(".submit").attr("lay-filter", "groupass").click(function () {
							layer.close(index);
							form.on('submit(groupass)', function (d) {
								var data = d.field;
								var groupid = {groupid: $select};
								data = Object.assign(data, groupid);
								$.ajax({
									type: "POST",
									url: "/backend/system/assignRoleGroup",
									cache: false,
									data: data,
									dataType: "json",
									success: function (e) {
										if (e.status === 1) {
											table.reload('group', {
												where: {
													groupid: $select,
													type: 1
												}
											});
											layer.alert(e.message, {
												//成功图标
												icon: 1
											});
										} else if (e.status === 0) {
											layer.alert(e.message, {
												//失败图标
												icon: 2
											});
										} else {
											layer.alert("系统错误，请稍后重试", {
												//失败图标
												icon: 2
											});
										}
									}
								});
								return false;
							});
						});
						laytpl.config({
							open: '{{',
							close: '}}'
						});
					}
				});
			},
			roleass: function () {
				$.ajax({
					type: "POST",
					url: "/backend/system/getPermissionList",
					cache: false,
					dataType: "json",
					data: {
						page: 0,
						limit: 10000
					},
					success: function (e) {
						var $select = $("select[name=role]").val(), $selecthtml = $("select[name=role] option:selected").html(), tmp;
						laytpl.config({
							open: '<%',
							close: '%>'
						});
						var index = layer.open({
							type: 1,
							title: false,
							closeBtn: true,
							area: '950px;',
							shade: 0.8,
							id: 'roleass',
							content: '<div class="layui-form layui-form-pane" style="padding:10px">' +
							'<fieldset class="layui-elem-field layui-field-title">' +
							'<legend>' + $selecthtml + '</legend>' +
							'</fieldset>' +
							'<div id="view"></div>' +
							'</div>'
						});
						$.ajax({
							type: "POST",
							url: "/backend/system/getRoleList",
							cache: false,
							dataType: "json",
							async: false,
							data: {
								page: 0,
								limit: 10000,
								type: 1,
								roleid: $select
							}
						}).done(function (ee) {
							tmp = _.sortBy(_.unionBy(_.values(ee.data), _.values(e.data), 'id'), function (item) {
								return item.id;
							});
						});
						var getTpl = check.innerHTML, view = document.getElementById('view');
						laytpl(getTpl).render(tmp, function (html) {
							view.innerHTML = html;
						});
						form.render('checkbox');
						$(".submit").attr("lay-filter", "roleass").click(function () {
							layer.close(index);
							form.on('submit(roleass)', function (d) {
								var data = d.field;
								var roleid = {roleid: $select};
								data = Object.assign(data, roleid);
								$.ajax({
									type: "POST",
									url: "/backend/system/assignRolePer",
									cache: false,
									data: data,
									dataType: "json",
									success: function (e) {
										if (e.status === 1) {
											table.reload('role', {
												where: {
													roleid: $select,
													type: 1
												}
											});
											layer.alert(e.message, {
												//成功图标
												icon: 1
											});
										} else if (e.status === 0) {
											layer.alert(e.message, {
												//失败图标
												icon: 2
											});
										} else {
											layer.alert("系统错误，请稍后重试", {
												//失败图标
												icon: 2
											});
										}
									}
								});
								return false;
							});
						});
						laytpl.config({
							open: '{{',
							close: '}}'
						});
					}
				});
			}
		};

		$('.layui-form-item .layui-btn').on('click', function () {
			var type = $(this).data('type');
			active[type] ? active[type].call(this) : '';
		});

		$('.per-tab .peradd').on('click', function () {
			var type = $(this).data('type');
			active[type] ? active[type].call(this) : '';
		});

		form.on('select(group)', function (data) {
			table.reload('group', {
				where: {
					groupid: data.value,
					type: 1
				}
			});
		});

		form.on('select(role)', function (data) {
			table.reload('role', {
				where: {
					roleid: data.value,
					type: 1
				}
			});
		});

		//监听工具条
		table.on('tool(group_table)', function (obj) {
			var data = obj.data;
			if (obj.event === 'del') {
				layer.confirm('确认要删除么？', function (index) {
					layer.close(index);
					$.ajax({
						type: "POST",
						url: "/backend/system/delRoleGroup",
						cache: false,
						data: {
							array: data
						},
						dataType: "json",
						success: function (e) {
							if (e.status === 1) {
								obj.del();
								$.ajax({
									type: "GET",
									url: "/backend/system/getGroupList",
									cache: false,
									dataType: "json",
									success: function (data) {
										var GROUP = data.data;
										var $group = $(".group");
										$group.empty();
										for (var i_GROUP in GROUP) {
											var o_GROUP = $("<option></option>");
											$(o_GROUP).val(GROUP[i_GROUP]['id']);
											$(o_GROUP).html(GROUP[i_GROUP]['name']);
											$group.append(o_GROUP);
										}
										form.render('select');
									}
								});
								layer.alert(e.message, {
									//成功图标
									icon: 1
								});
							} else if (e.status === 0) {
								layer.alert(e.message, {
									//失败图标
									icon: 2
								});
							} else {
								layer.alert("系统错误，请稍后重试", {
									//失败图标
									icon: 2
								});
							}
						}
					})
				});
			} else if (obj.event === 'name') {
				layer.prompt({
						title: '修改名称',
						value: data.name
					},
					function (value, index) {
						layer.close(index);

						ajax_send(data, "name", value, "editGroup");
						obj.update({name: value})
					}
				);
			} else if (obj.event === 'description') {
				layer.prompt({
						title: '修改描述',
						value: data.description
					},
					function (value, index) {
						layer.close(index);

						ajax_send(data, "description", value, "editGroup");
						obj.update({description: value});
					}
				);
			}
		});

		table.on('tool(role_table)', function (obj) {
			var data = obj.data;
			if (obj.event === 'del') {
				layer.confirm('确认要删除么？', function (index) {
					layer.close(index);
					$.ajax({
						type: "POST",
						url: "/backend/system/delRolePer",
						cache: false,
						data: {
							array: data
						},
						dataType: "json",
						success: function (e) {
							if (e.status === 1) {
								obj.del();
								$.ajax({
									type: "GET",
									url: "/backend/system/getRoleList",
									cache: false,
									dataType: "json",
									success: function (data) {
										var ROLE = data.data;
										var $role = $(".role");
										$role.empty();
										for (var i_ROLE in ROLE) {
											var o_ROLE = $("<option></option>");
											$(o_ROLE).val(ROLE[i_ROLE]['id']);
											$(o_ROLE).html(ROLE[i_ROLE]['name']);
											$role.append(o_ROLE);
										}
										form.render('select');
									}
								});
								layer.alert(e.message, {
									//成功图标
									icon: 1
								});
							} else if (e.status === 0) {
								layer.alert(e.message, {
									//失败图标
									icon: 2
								});
							} else {
								layer.alert("系统错误，请稍后重试", {
									//失败图标
									icon: 2
								});
							}
						}
					})
				});
			} else if (obj.event === 'name') {
				layer.prompt({
						title: '修改名称',
						value: data.name
					},
					function (value, index) {
						layer.close(index);

						ajax_send(data, "name", value, "editRole");
						obj.update({name: value})
					}
				);
			} else if (obj.event === 'description') {
				layer.prompt({
						title: '修改描述',
						value: data.description
					},
					function (value, index) {
						layer.close(index);

						ajax_send(data, "description", value, "editRole");
						obj.update({description: value});
					}
				);
			}
		});

		table.on('tool(per_table)', function (obj) {
			var data = obj.data;
			if (obj.event === 'del') {
				layer.confirm('确认要删除么？', function (index) {
					layer.close(index);
					$.ajax({
						type: "POST",
						url: "/backend/system/delPer",
						cache: false,
						data: {
							id: data.id
						},
						dataType: "json",
						success: function (e) {
							if (e.status === 1) {
								obj.del();
								table.reload('per');
								layer.alert(e.message, {
									//成功图标
									icon: 1
								});
							} else if (e.status === 0) {
								layer.alert(e.message, {
									//失败图标
									icon: 2
								});
							} else {
								layer.alert("系统错误，请稍后重试", {
									//失败图标
									icon: 2
								});
							}
						}
					})
				});
			} else if (obj.event === 'name') {
				layer.prompt({
						title: '修改名称',
						value: data.name
					},
					function (value, index) {
						layer.close(index);

						ajax_send(data, "name", value, "editRole");
						obj.update({name: value});
					}
				);
			} else if (obj.event === 'description') {
				layer.prompt({
						title: '修改描述',
						value: data.description
					},
					function (value, index) {
						layer.close(index);

						ajax_send(data, "description", value, "editRole");
						obj.update({description: value});
					}
				);
			} else if (obj.event === 'path') {
				layer.prompt({
						title: '修改控制路径',
						value: data.path
					},
					function (value, index) {
						layer.close(index);

						ajax_send(data, "path", value, "editRole");
						obj.update({path: value});
					}
				);
			} else if (obj.event === 'status') {
				layer.prompt({
						title: '修改可用状态',
						value: data.status
					},
					function (value, index) {
						layer.close(index);

						ajax_send(data, "status", value, "editRole");
						obj.update({status: value});
					}
				);
			}
		});

		function ajax_send(data, name, value, action) {
			$.ajax({
				type: "POST",
				url: "/backend/system/" + action,
				cache: false,
				data: {
					id: data.id,
					k: name,
					v: value
				},
				dataType: "json",
				success: function (e) {
					if (e.status === 1) {
						layer.alert(e.message, {
							//成功图标
							icon: 1
						});
					} else if (e.status === 0) {
						layer.alert(e.message, {
							//失败图标
							icon: 2
						});
					} else {
						layer.alert("系统错误，请稍后重试", {
							//失败图标
							icon: 2
						});
					}
				}
			});
		}
	});
</script>
{/block}